package com.example.mybatisplusdemo.Controller;


import com.example.mybatisplusdemo.Result.Result;
import com.example.mybatisplusdemo.Service.AdminService;
import com.example.mybatisplusdemo.Service.BusinessService;
import com.example.mybatisplusdemo.Service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class TokenController {
    @Resource
    AdminService adminService;
    @Resource
    BusinessService businessService;
    @Resource
    UserService userService;

    /**
     * admin token验证
     * @param token
     * @return
     */
    @PostMapping("/checkadmin")
    public Result checkadmin(@RequestParam("token") String token){
        if (adminService.checktoken(token)){
            return new Result(200,"权限验证通过");
        }else{
            return new Result(400,"权限验证失败");
        }
    }

    /**
     * bus token 验证
     * @param token
     * @return
     */
    @PostMapping("/checkbus")
    public Result checkbus(@RequestParam("token") String token){
        if (businessService.checktoken(token)){
            return new Result(200,"权限验证通过");
        }else{
            return new Result(400,"权限验证失败");
        }
    }

    /**
     * user token 验证
     * @param token
     * @return
     */
    @PostMapping("/checkuser")
    public Result checkuser(@RequestParam("token") String token){
        if (userService.checktoken(token)){
            return new Result(200,"权限验证通过");
        }else{
            return new Result(400,"权限验证失败");
        }
    }
}
